var avatarUp0, avatarUp1, avatarUp2 = "";

function iconTypeChange() {
    avatarUp0 = new $IconUpload("avatar0");
    avatarUp0.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
    avatarUp2 = new $IconUpload("avatar2");
    avatarUp2.initIcon();
}

$(function () {
    iconTypeChange();
    $("#first_Content_nav > div").eq(0).click();
});

$("#first_Content_nav > div").click(function () {
    var index = $(this).index();
    $(this).addClass('selection').siblings().removeClass('selection');
    $("#first_Content_con > div").eq(index).show().siblings().hide();
    iconTypeChange();
});

function firstClose() {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
}

function storageRepair() {
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var customerName=$("#customerName",parent.document).val();
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    if(doctor===null || doctor==="" || doctor===undefined){
        Feng.error("医生不能为空！");
        return false;
    }
    if(nurse===null || nurse==="" || nurse===undefined){
        Feng.error("护士不能为空！");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/storageRepair",
        type: "post",
        data: {
            "num": num,
            "reservationsId": reservationsId,
            "customerName": customerName,
            "doctor": doctor,
            "nurse": nurse
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.uploadRepairScoreTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function subRepair() {
    if($("#avatar0PreId").children().length <= 0 || $("#avatar1PreId").children().length <= 0 || $("#avatar2PreId").children().length <= 0){
        Feng.error("请补全照片！");
        return false;
    }
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var customerName=$("#customerName",parent.document).val();
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    if(doctor===null || doctor==="" || doctor===undefined){
        Feng.error("医生不能为空！");
        return false;
    }
    if(nurse===null || nurse==="" || nurse===undefined){
        Feng.error("护士不能为空！");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/subRepair",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "customerName": customerName,
            "doctor": doctor,
            "nurse": nurse
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.uploadRepairScoreTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

$('#avatar0PreId,#avatar1PreId,#avatar2PreId').on('click', '.cp_img_delete', function (e) {
    e.stopPropagation();
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/deleteRepairImgs",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $(that).parent().remove();
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});